#include "NumStr.h"

#include "PTime.h"

#include <time.h>

PTime::PTime()
{
	struct tm *newtime;
	long ltime;
	time( &ltime );
	newtime = localtime ( &ltime );
	
	m_hour = newtime->tm_hour;
	m_min = newtime->tm_min;
	m_sec = newtime->tm_sec;
	
	m_day = newtime->tm_mday;
	m_mon = newtime->tm_mon+1;
	m_year = newtime->tm_year+1900;

	m_time = ltime;
}

PTime::PTime(const PTime& t):
        m_hour( t.m_hour ),
         m_min( t.m_min  ),
         m_sec( t.m_sec  ),
         m_day( t.m_day  ),
         m_mon( t. m_mon ),
        m_year( t.m_year ),
        m_time( t.m_time )
{
}

PTime::PTime(
        int  hour,
        int   min,
        int   sec,
        int   day,
        int   mon,
        int  year,
        long time
        ):
    m_hour( hour ),
     m_min(  min ),
     m_sec(  sec ),
     m_day(  day ),
     m_mon(  mon ),
    m_year( year ),
    m_time( time )
{

}

PTime& PTime::operator = ( const PTime& t )
{
    m_hour = t.m_hour;
     m_min = t.m_min;
     m_sec = t.m_sec;
     m_day = t.m_day;
     m_mon = t. m_mon;
    m_year = t.m_year;
    m_time = t.m_time;
    return *this;
}

void PTime::Now(void)
{
	struct tm *newtime;

	long ltime;
	time( &ltime );
	newtime = localtime ( &ltime );
	
    m_hour = newtime->tm_hour;
	m_min = newtime->tm_min;
	m_sec = newtime->tm_sec;
	
	m_day = newtime->tm_mday;
	m_mon = newtime->tm_mon+1;
	m_year = newtime->tm_year+1900;

	m_time = ltime;
}

string PTime::StrTime(void) const
{
	string str, sec;
	NumStr s;
    s.setPrecision(0);
	str=s.conv(m_hour);
	str.append(":");
	str.append(s.conv(m_min));
	str.append(":");
	if (s.conv(m_sec).length() == 1) str.append("0");
	str.append(s.conv(m_sec));
	return(str);
}

string PTime::StrDate(void) const
{
	string str;
	NumStr s;
    s.setPrecision(0);
	str=s.conv(m_day);
	str.append("/");
	str.append(s.conv(m_mon));
	str.append("/");
	str.append(s.conv(m_year));
	return(str);
}

string PTime::Str(void) const
{
	string str;
	NumStr s;
    s.setPrecision(0);
	str=s.conv(m_hour);
	str.append(":");
	str.append(s.conv(m_min));
	str.append(":");
	str.append(s.conv(m_sec));
	str.append(" - ");
	str.append(s.conv(m_day));
	str.append("/");
	str.append(s.conv(m_mon));
	str.append("/");
	str.append(s.conv(m_year));
	return(str);
}

int  PTime::getHour ( void ) const { return m_hour; }
int   PTime::getMin ( void ) const { return m_min; }
int   PTime::getSec ( void ) const { return m_sec; }
int   PTime::getDay ( void ) const { return m_day; }
int   PTime::getMon ( void ) const { return m_mon; }
int  PTime::getYear ( void ) const { return m_year; }
long PTime::getTime ( void ) const { return m_time; }

void  PTime::setHour (  int hour ) { m_hour = hour; }
void   PTime::setMin (  int  min ) { m_min = min; }
void   PTime::setSec (  int  sec ) { m_sec = sec; }
void   PTime::setDay (  int  day ) { m_day = day; }
void   PTime::setMon (  int  mon ) { m_mon = mon; }
void  PTime::setYear (  int year ) { m_year = year; }
void  PTime::setTime ( long time ) { m_time = time; }
